package com.genesis.web.controller;


import com.genesis.mall.common.PageInfo;
import com.genesis.mall.common.Result;
import com.genesis.mall.entity.SmsFlashPromotionProductRelation;
import com.genesis.mall.service.ISmsFlashPromotionProductRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品限时购与商品关系表 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-08-01
 */
@RestController
@RequestMapping("/flashProductRelation")
public class SmsFlashPromotionProductRelationController {

    @Autowired
    private ISmsFlashPromotionProductRelationService sFPPtRService;

    /**
     * 批量选择
     *
     * @param smsFlashPromotionProductRelation
     * @return
     */
    @PostMapping("/create")
    public Result create(@RequestBody List<SmsFlashPromotionProductRelation> smsFlashPromotionProductRelation) {
        sFPPtRService.create(smsFlashPromotionProductRelation);
        return Result.success();
    }

    /**
     * 删除关联
     *
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public Result deleteById(@RequestParam int id) {
        sFPPtRService.removeById(id);
        return Result.success();
    }


    /**
     * 修改关联信息
     *
     * @param smsFlashPromotionProductRelations
     * @return
     */
    @PostMapping("/update/{id}")
    public Result updateById(@RequestBody SmsFlashPromotionProductRelation smsFlashPromotionProductRelations) {
        sFPPtRService.updateBy(smsFlashPromotionProductRelations);
        return Result.success();
    }

    /**
     * 分页查询不同场次关联及商品信息
     * @param flashPromotionId
     * @param flashPromotionSessionId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public Result listall(Integer flashPromotionId, Integer flashPromotionSessionId, Integer pageNum, Integer pageSize) {
        PageInfo info = sFPPtRService.listAll(flashPromotionId, flashPromotionSessionId, pageNum, pageSize);
        return Result.success();
    }

    /**
     * h获取商品管理促销
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@RequestParam int id){
        SmsFlashPromotionProductRelation byId = sFPPtRService.getById(id);
        return Result.success(byId);
    }
}